package com.niit.controller.hive;

import java.sql.*;

public class YouTube2 {
    private static String driverClass = "org.apache.hive.jdbc.HiveDriver";
    public static void main(String[] args) throws SQLException {

        try {
            Class.forName(driverClass);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        Connection connection = DriverManager.getConnection("jdbc:hive2://hadoop:10000/default","root","niit1234");
        Statement statement = connection.createStatement();

        String table_name ="youtube";
        String query1 = "select category, sum(no_of_views ) as snum from "+table_name+" group by category order by snum limit 10";

        ResultSet result = statement.executeQuery(query1);
        int[] snum = new int[9];
        String[] category = new String[9];
        int i = 0;
        while(result.next()) {
            category[i] = result.getString(1);
            snum[i] = result.getInt(2);
            i++;
            System.out.println("col1 : "+result.getInt(1));
            System.out.println("col2 : "+result.getString(2));
            System.out.println("col3 : "+result.getString(3));
            System.out.println("col4 : "+result.getInt(4));
            System.out.println("col5 : "+result.getInt(5));
            System.out.println("col6 : "+result.getString(6));
            System.out.println("col7 : "+result.getString(7));
            System.out.println("col8 : "+result.getInt(8));
        }
        result.close();
        statement.close();
        connection.close();

    }
}